<?php
namespace tuling;

class AIchat
{
    public function getStr($str){
        $url = 'http://openapi.tuling123.com/openapi/api/v2';
        $post_arr = [
            "reqType" => 0,
            "perception" => [
                "inputText" => [
                    "text" => $str,
                ],
            ],
            "userInfo" => [
                "apiKey" => '27a3c53e513c4a198545b9baf986ed72',
                "userId" => '279482',
            ],
        ];

        $post = json_encode($post_arr,JSON_UNESCAPED_UNICODE);
        $return = httpRequest($url , 'POST' , $post);
        
        $ret_arr = json_decode($return,true);
        if($ret_arr['results'][0]['resultType'] == 'text'){
            $text = $ret_arr['results'][0]['values']['text'];
            return $text;
        }
    }
}